#include<iostream>
#include <string>
#include <queue>
using namespace std;
typedef struct node{
    char data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
BTNode*CreateBT1(char *pre,char *in,int n);
int GetHeight(BTNode* BT);
int main(){
	int n,i=0;
	BTNode *BT1;
	cin>>n;
	char pre[n],in[n],a;
	for(i=0;i<n;i++){
		cin>>pre[i];
	}
	for(i=0;i<n;i++){
		cin>>in[i];
	}
	BT1=CreateBT1(pre,in,n);
	cout<<GetHeight(BT1);
	return 0;
	
}
BTNode*CreateBT1(char *pre,char *in,int n){
	BTNode *BT;
	char *p;
	int k;
	if(n<=0) return NULL;
	BT=new BTNode;
	BT->data=*pre;
	for(p=in;p<in+n;p++){
		if(*p==*pre) break;
	}
	k=p-in;
	BT->lchild=CreateBT1(pre+1,in,k);
	BT->rchild=CreateBT1(pre+k+1,in+k+1,n-k-1);
	return BT;
}
int GetHeight(BTNode* BT){
	int L,D;
	if(BT==NULL){
		return 0;
	}
	else{
		L=GetHeight(BT->lchild);
		D=GetHeight(BT->rchild);
		if(L>=D) return L+1;
		else{
			return D+1;
		}
		
	}
}
